/*
 ============================================================================
 Name		: InputDataView.cpp
 Author	  : Vanderson Rodrigues
 Version	 : 1.0
 Copyright   : Your copyright notice
 Description : CInputDataView implementation
 ============================================================================
 */

// INCLUDE FILES
#include  <aknviewappui.h>
#include  <avkon.hrh>

#include  "DepositForm.h"
//For Toolbar API
#include <aknappui.h>
#include <AknToolbar.h>
#include <akntoolbarobserver.h>

#include <symcontrol_0xE0D9D958.rsg>

//Generated User Includes
#include  "InputDataViewContainer.h" 
#include "InputDataView.h"
#include  "symcontrol.hrh"
#include "symcontrol_0xE0D9D958.hlp.hrh"


void CInputDataView::ConstructL( )
{
    BaseConstructL( R_INPUTDATAVIEW );
}

CInputDataView::~CInputDataView()
{
    if ( iContainer )
        {
        AppUi()->RemoveFromViewStack( *this, iContainer );
        }

    delete iContainer;
}

TUid CInputDataView::Id() const
{
    return KVDataInputView;
}

void CInputDataView::HandleCommandL( TInt aCommand )
{
    TBool commandHandled = EFalse;
    
    switch( aCommand )
    {
        case ECommand1:
            User::InfoPrint( _L("DEBUG: ECommand1") );
            _LIT(KInitialValue, "Initialize");
            
            /**TODO:
             * Remove this code from here.. Just test for now.
             **/
            CDepositForm* form = CDepositForm::NewL();
            TInt ret = form->ExecuteLD( R_DEPOSIT_FORM_DIALOG );
            
            break;
        case EAknSoftkeyExit:
            AppUi()->HandleCommandL( EEikCmdExit );
            break;
        default:
            break;
    }
    
    if( !commandHandled )
    {
        AppUi()->HandleCommandL( aCommand );
    }
}

void CInputDataView::HandleClientRectChange()
{
    if( iContainer )
    {
       iContainer->SetRect( ClientRect() );
    }
}

void CInputDataView::DoActivateL( const TVwsViewId& /*aPrevViewId*/, TUid /*aCustomMessageId*/,
                                  const TDesC8& /*aCustomMessage*/)
{
    if( !iContainer )
    {
        iContainer = new ( ELeave ) CInputDataViewContainer;
        iContainer->SetMopParent( this );
        iContainer->ConstructL( ClientRect() );
        AppUi()->AddToStackL( *this, iContainer );
    }

    //    Set this to toolbar observer
    if( AppUi()->CurrentFixedToolbar() )
    {
        AppUi()->CurrentFixedToolbar()->SetToolbarObserver( this );
    }
}

void CInputDataView::DoDeactivate()
{
    if( iContainer )
    {
        AppUi()->RemoveFromViewStack( *this, iContainer );
    }

    delete iContainer;
    iContainer = NULL;
}

////From MAknToolbarObserver
void CInputDataView::OfferToolbarEventL(TInt aCommand)
{
    HandleCommandL(aCommand);
}

